auto.waitFor();

var width = device.width;
var height = device.height;
setScreenMetrics(width, height);

var tu = false;
var dian = true;
if(tu) {
    threads.start(function () {
        text("立即开始").findOne(3000).click();
    });
    if (!requestScreenCapture()) {
        toast("请求截图失败");
        exit();
    }
}


toast("将开始点击");
sleep(1000);
toast("请切换至立即开始页面");
textContains("开启").findOne(1000).click();
sleep(2000);
var b = [80, 160, 240, 320, 400, 480, 560, 640, 720, 800, 880, 960, 1040];
var sudu = 10;
var delay = 50;
var thread1 = threads.start(function () {
    var x = 500;
    var y = 850;
    var delta = 100;

    while (tu) {
        var time_start = new Date();
        var point = findColorInRegion(captureScreen(), "#219300", 100, 0.125 * height, 0.9 * width, 300);
        if (point) {
            x = point.x + 20;
            var time_end = new Date();
            delta = (time_end.getTime() - time_start.getTime()) / 30 * 100

            y = point.y + delta;
            press(x, y, 40);
            sleep(delay);
        } else {
            press(x, y, 40);
            sleep(delay);
        }
    }
    while(dian) {
        for (var index = 1; index < b.length; index++) {
            press(b[index], 369, sudu);
        }
    }
});



threads.start(function () {
    sleep(15500);
    sudu = 1000;
    delay = 1000;
    textContains("再来一次").findOne(3000).click();
    sleep(1500);
    sudu = 10;
    delay = 50;
});

textContains("蚂蚁").waitFor();
thread1.interrupt();

toast("结束");
exit();

                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                                            
                                                                     
